package com.ofsoft.weixin.mp;

import com.ofsoft.weixin.mp.message.DefaultController;
import com.ofsoft.weixin.mp.message.MessageController;
import com.ofsoft.weixin.mp.message.MessageHandler;
import com.ofsoft.weixin.mp.message.MessageHandlerBase;

/**
 * 处理器工厂
 * 
 * @author OF
 * @date 2017年10月10日
 */

public class HandlerFactory {
	public static MessageHandlerBase messageHandlerBase = null;

	public static MessageHandlerBase getMessageHandler() {
		if (messageHandlerBase == null) {
			messageHandlerBase = new MessageHandler();
		}
		return messageHandlerBase;
	}

	public static void setMessageHandler(MessageHandlerBase messageController) {
		HandlerFactory.messageHandlerBase = messageController;
	}

	public static MessageController messageController = null;

	public static void setMessageController(MessageController messageController) {
		HandlerFactory.messageController = messageController;
	}

	public static MessageController getMessageController() {
		if (messageController == null) {
			messageController = new DefaultController();
		}
		return messageController;
	}

	public static void setMessageController(Class<?> newInstance) {
		try {
			messageController = (MessageController) newInstance.newInstance();
		} catch (InstantiationException | IllegalAccessException e) {
			e.printStackTrace();
		}

	}
}
